package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.TbDiscountMapper;
import com.bwie.mapper.TbShopMapper;
import com.bwie.mapper.TbTypeMapper;
import com.bwie.pojo.TbDiscount;
import com.bwie.pojo.TbInfo;
import com.bwie.pojo.TbShop;
import com.bwie.pojo.TbType;
import com.bwie.service.TbInfoService;
import com.bwie.mapper.TbInfoMapper;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 叶雨洁
* @description 针对表【tb_info】的数据库操作Service实现
* @createDate 2025-07-15 13:02:17
*/
@Service
public class TbInfoServiceImpl extends ServiceImpl<TbInfoMapper, TbInfo>
    implements TbInfoService{


    @Autowired
    TbInfoMapper infoMapper;

    @Autowired
    TbShopMapper shopMapper;

    @Autowired
    TbTypeMapper typeMapper;

    @Autowired
    TbDiscountMapper discountMapper;
    @Override
    public R getInfoList(PageInfoVo pageInfoVo) {

        Page<TbInfo> tbInfoPage = new Page<>(pageInfoVo.getPageNum(),pageInfoVo.getPageSize());
        QueryWrapper<TbInfo> tbInfoQueryWrapper = new QueryWrapper<>();
        Page<TbInfo> tbInfoPage1 = infoMapper.selectPage(tbInfoPage, tbInfoQueryWrapper);
        return R.OK(tbInfoPage1);
    }

    @Override
    public R getShopList(PageInfoVo pageInfoVo) {

        Page<TbShop> tbShopPage = new Page<>(pageInfoVo.getPageNum(),pageInfoVo.getPageSize());
        QueryWrapper<TbShop> wrapper = new QueryWrapper<>();
        Page<TbShop> tbShopPage1 = shopMapper.selectPage(tbShopPage, wrapper);
        return R.OK(tbShopPage1);
    }

    @Override
    public R getTypeList() {

        List<TbType> tbTypes = typeMapper.selectList(null);
        return R.OK(tbTypes);
    }

    @Override
    public R updateStatus(TbInfo info) {

        info.setTypeId(2);
        infoMapper.updateById(info);
        return R.OK();
    }

    @Override
    public R disCount() {

        List<TbDiscount> tbDiscounts = discountMapper.selectList(null);
        return R.OK(tbDiscounts);
    }

    @Override
    public R useDiscount(TbShop tbShop) {


        tbShop.setStatusId(1);
        shopMapper.updateById(tbShop);
        return R.OK();
    }
}




